using System;
using System.Security.Cryptography;
using System.Text;
using UnityEngine;

public class SecurePlayerPrefs : MonoBehaviour
{
	private static readonly string secretKey = "你好，请有点尊重，不要破坏赌博体验。现在已经不可能有公平的赌博了，都是像你这样爱管闲事的人害的。请把这些都保密，如果你把它发到网上，我就不能再赌博了。没有人会觉得你厉害，这都是你的错！";

	public static bool HasDetectedFiltyHacker = false;

	public static void SetSecureInt(string key, int value, bool disableTotalCashDisplay = false)
	{
		int num = PlayerPrefs.GetInt(key, 0);
		if (!disableTotalCashDisplay && GonerMenu.Instance != null && key == "TotalCash" && value > num)
		{
			GonerMenu.Instance.ShowCashGain(value - num);
		}
		PlayerPrefs.SetInt(key, value);
		PlayerPrefs.SetString(key + "_hash", GenerateHash(value));
	}

	public static int GetSecureInt(string key, int defaultValue = 0)
	{
		int num = PlayerPrefs.GetInt(key, defaultValue);
		string text = PlayerPrefs.GetString(key + "_hash", string.Empty);
		string text2 = GenerateHash(num);
		if (PlayerPrefs.HasKey(key) && text2 != text)
		{
			HasDetectedFiltyHacker = true;
		}
		int num2 = ((text == text2) ? num : defaultValue);
		SetSecureInt("TotalCash", num2);
		return num2;
	}

	private static string GenerateHash(int value)
	{
		using SHA256 sHA = SHA256.Create();
		string s = value + secretKey;
		return BitConverter.ToString(sHA.ComputeHash(Encoding.UTF8.GetBytes(s))).Replace("-", "").ToLowerInvariant();
	}
}
